package com.sscw.task.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.sscw.task.entity.MRecordProductCardPO;
import com.sscw.task.mapper.MRecordProductCardMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MRecordProductCardDAO extends BaseDAO<MRecordProductCardMapper, MRecordProductCardPO> {

    public List<MRecordProductCardPO> findNeedGrantCard() {
        LambdaQueryWrapper<MRecordProductCardPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(MRecordProductCardPO::getRemainDay, 0);
        return getBaseMapper().selectList(queryWrapper);
    }

    public int reduceDay(List<Long> ids) {
        LambdaUpdateWrapper<MRecordProductCardPO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setSql("remain_day = remain_day-1");
        updateWrapper.in(MRecordProductCardPO::getId, ids);
        return getBaseMapper().update(new MRecordProductCardPO(), updateWrapper);
    }
}
